<template>
    <div
        class="ff-cell ff-cell-checkbox"
        :class="!disabled && currentValue? 'ff-cell-checkbox-checked' : ''"
        :style="'width:' + width + 'px;'"
    >
        <div class="ff-image" :style="'width:' + width + 'px;height:'+ height + 'px'">
            <div class="c-map" @click="goCommodity">
                <img :src="imageLink"/>
            </div>
            <div v-if="showNewFocus" class="ff-focus-position" @click.stop="focusClick">
                <i class="iconfont icon-yishoucang" :class="focus? 'red' : ''"></i>
            </div>
            <div class="ff-sales">
                <span class="left-text" v-if="weekAverage !== -1">周日均{{weekAverage}}</span>
                <span class="left-text" v-if="dateUpDays && !hide">{{dateUpDays}}</span>
                <span class="right-text" v-if="!hide">周销量{{volume}}</span>
            </div>
            <div class="ff-cell-off-mask"></div>
        </div>
        <div class="ff-image-list">
            <swiper :options="swiperOption" class="ff-image-list-swiper" ref="mySwiper">
                <swiper-slide
                    :key="index"
                    v-for="(item, index) of imgList"
                >
                    <span class="ff-image-active" v-if="index === active"></span>
                    <span class="ff-image-list--single" @mouseover="imgSelect(item, index)">
                        <img class="swiper_img" :src="`${item.src}?x-oss-process=image/resize,m_pad,h_33,w_33`" alt="" />
                    </span>
                </swiper-slide>
            </swiper>
            <div class="ff-image-list-prev" slot="button-prev" :class="`prev-${logo}`"><i class="iconfont icon-zuojiantou"></i></div>
            <div class="ff-image-list-next" slot="button-next" :class="`next-${logo}`"><i class="iconfont icon-youjiantou"></i></div>
        </div>
        <div class="ff-text" @click="handleValueClick">
            <span v-if="ranking !== ''" class="ff-text-ranking" v-html="ranking"></span>
            <span v-if="arriveDate !== ''" class="ff-text-arriveDate">预计<span>{{arriveDate}}</span>到达</span>
            <label class="ff-price">
                ¥{{presentPrice.toFixed(2)}}
                <span v-if="tagPrice > 0" class="under-price">¥{{tagPrice.toFixed(2)}}</span>
            </label>
            <a class="ff-commodity">
                <span>{{ecode}}{{name}}</span>
            </a>
            <span class="ff-text-inform" v-if="inform">{{inform}}</span>
            <div v-if="showFocus" class="ff-focus-text">
                <label class="left-focus" @click.stop="focusClick">收藏商品<i class="iconfont" :class="focus?'icon-yishoucang red':'icon-shoucang'"></i></label>
                <label class="right-focus">已收藏{{focusSum}}</label>
            </div>
            <div v-if="showNewFocus" class="ff-focus-text-new">
                <label class="left-focus" @click.stop="reservationClick">
                    <i class="iconfont icon-shijian" :class="reservation?'red' : ''"></i>
                    <span>{{reservation? '已预定' : '预定'}}({{reservationSum}})</span>
                </label>
                <label class="left-focus cursorDef" @click="goCommodity(true)">
                    <i class="iconfont" :class="isEvaluated? 'icon-pingjia_huaban red' : 'icon-pingjia'"></i>
                    <span>{{isEvaluated? '已评价' : '评价'}}({{evaluationSum}})</span>
                </label>
            </div>
        </div>
        <span
            class="checkbox-true"
            v-if="!disabled && currentValue"
        >
            <i class="iconfont icon-xuanzhongjiaobiao"></i>
        </span>
    </div>
</template>
<script>
    import 'swiper/dist/css/swiper.css'
    import { swiper, swiperSlide } from 'vue-awesome-swiper'
    export default {
        name: 'FfCell',
        props: {
            ecode: {//商品款号
                type: String,
                default: ''
            },
            name: {//商品名称(款号 商品名)
                type: String,
                default: '',
            },
            imageUrl: {//商品主图链接
                type: String,
            },
            imgList: {//商品图片列表
                type: Array,
                default: () => []
            },
            ranking: {//商品的名次
                type: String,
                default: '',
            },
            arriveDate: {//到店日期
                type: String,
                default: ''
            },
            inform: {//臂长,袖长信息
                type: String,
                default: ''
            },
            dateUpDays: {//上市日期
                type: String,
                default: ''
            },
            hide: { // 是否隐藏周销量和上市日期
                type: Boolean,
                default: false,
            },
            volume: {//周销量
                type: Number,
                default: 0,
            },
            weekAverage: {//周日均
                type: Number,
                default: -1,
            },
            presentPrice: {//现价
                type: Number,
                default: 0,
            },
            tagPrice: {//吊牌价,不提供就不显示
                type: Number,
                default: 0,
            },
            disabled: {//是否可以编辑选择删除(可以编辑(false) 不可编辑(true))
                type: Boolean,
                default: false,
            },
            value: {//是否选择 v-model值
                type: Boolean,
                default: false,
            },
            showFocus: {//是否显示最后一行,关注相关信息
                type: Boolean,
                default: false,
            },
            showNewFocus: {//是否显示新版的关注和预定
                type: Boolean,
                default: false,
            },
            focus: {//是否已关注
                type: Boolean,
                default: false,
            },
            reservation: {//是否已预定
                type: Boolean,
                default: false,
            },
            isEvaluated: {//是否已评价
                type: Boolean,
                default: false,
            },
            reservationSum: {//预定数量
                type: [Number, String],
                default: 0,
            },
            focusSum: {//关注总数量
                type: [Number, String],
                default: 0,
            },
            evaluationSum: {//评价总数量
                type: [Number, String],
                default: 0,
            },
            height: {
                type: Number,
                default: 206,
            },
            width: {
                type: Number,
                default: 196,
            }
        },
        components: {
            swiper,
            swiperSlide
        },
        data() {
            let data = (new Date()).getTime();
            return {
                swiperOption: {
                    loop: false,
                    observer: true,//修改swiper自己或子元素时，自动初始化swiper
                    observeParents: true,//修改swiper的父元素时，自动初始化swiper
                    spaceBetween: 5, //间距
                    direction: 'horizontal',//轮播方向
                    onlyExternal: true,//不允许拖动
                    slidesPerView: 4,//一页展示几个
                    navigation: {
                        prevEl: `.prev-${data}`,
                        nextEl: `.next-${data}`,
                    }
                },
                logo: data,//标识,防止多个swiper相互影响
                active: 0,//图片选中边框高亮
            }
        },
        computed: {
            swiper() {
                return this.$refs.mySwiper.swiper
            },
            imageLink: {
                get () {
                    if(this.imageUrl){
                        if(this.imageUrl.indexOf('?x-oss-process') > 0) {
                            return this.imageUrl;
                        }
                        return this.imageUrl + `?x-oss-process=image/resize,m_pad,h_${this.height},w_${this.width},color_ffffff`;
                    }
                    return this.$store.state.static;
                },
                set (val) {
                    this.$emit('update:imageUrl', val);
                }
            },
            /*控制选中*/
            currentValue: {
                get: function () {
                    return this.value;
                },
                set: function (val) {
                    this.$emit("input", val);
                }
            }
        },
        mounted() {

        },
        methods: {
            /*选中当前款*/
            handleValueClick() {
                if(!this.disabled) {
                    this.currentValue = !this.currentValue;
                    this.$emit('handleValueClick');
                }
            },
            /*点击预定*/
            reservationClick () {
                this.$emit('reservationClick');
            },
            /*点击收藏*/
            focusClick($event) {
                this.$emit('focusClick', $event);
            },
            /*选择图片*/
            imgSelect (item, index) {
                this.active = index;
                this.imageLink = item.src;
            },
            /*前往商品详情网站*/
            goCommodity (status) {
                this.$router.push({
                    path: '/commodityDetails',
                    query: {
                        sku: this.ecode,
                        status: status? 'second' : 'first'
                    }
                })
            }
        }
    }
</script>
<style lang="less" type="text/less">
    @red: #E80000;
    @font-light-black: #575757;
    @font-black: #333;
    @font-light-grey: #BBBBBB;
    @orange: #fd6442;
    .ff-cell {
        display: inline-block;
        position: relative;
        border-radius: 4px;
        border: 1px solid transparent;
        div {
            max-width: 100%;
            max-height: 100%;
        }
        .ff-image {
            position: relative;
            z-index: 0;
            overflow: hidden;
            .c-map {
                text-align: center;
                height: 100%;
                img {
                    //border-radius: 6px;
                    max-width: 100%;
                    max-height: 100%;
                    height: 100%;
                }
            }
            .ff-focus-position {
                display: none;
                position: absolute;
                right: 6px;
                top: 7px;
                background-color: #fff;
                width: 35px;
                height: 35px;
                text-align: center;
                line-height: 40px;
                border: 1px solid #ccc;
                border-radius: 4px;
                cursor: pointer;
                .iconfont {
                    font-size: 20px;
                    color: #999;
                }
                .red {
                    color: #FD6442;
                }
                &:hover {
                    display: block;
                }
            }
            .c-map:hover + .ff-focus-position {
                display: block;
            }
            .ff-sales {
                background-color: rgba(0, 0, 0, 0.3);
                bottom: 0;
                left: 0;
                height: 22px;
                line-height: 22px;
                right: 0;
                padding: 0 10px;
                position: absolute;
                .left-text {
                    color: #f5f5f5;
                    font-size: 12px;
                }
                .right-text {
                    color: #f5f5f5;
                    float: right;
                    font-size: 12px;
                    vertical-align: middle;
                }
            }
        }
        .ff-text {
            padding: 10px 0 0;
            position: relative;
            text-align: center;
            z-index: 3;
            .ff-price {
                color: @red;
                height: 26px;
                line-height: 24px;
                font-size: 18px;
                display: block;
                position: relative;
                text-align: center;
                .under-price {
                    color: @font-light-black;
                    font-size: 14px;
                    text-decoration: line-through;
                }
            }
            .ff-commodity {
                color: @font-black;
                cursor: pointer;
                display: block;
                font-size: 12px;
                margin: 0 10px 10px;
                /*height: 36px;*/
                line-height: 18px;
                text-align: center;
                overflow: hidden;
                text-overflow: ellipsis;
                display: -webkit-box;
                -webkit-line-clamp: 2;
                -webkit-box-orient: vertical;
                word-wrap: break-word;
                &:hover{
                    text-decoration: none;
                }
            }
            .ff-focus-text, .ff-focus-text-new {
                color: #868686;
                height: 16px;
                line-height: 16px;
                text-align: left;
                margin-bottom: 8px;
                .left-focus {
                    cursor: pointer;
                    display: inline-block;
                    margin-left: 14px;
                    .iconfont {
                        margin-left: 3px;
                        font-size: 12px;
                        &.red {
                            color: #fd6442;
                        }
                    }
                }
                .right-focus {
                    float: right;
                    margin-right: 14px;
                }
            }
            .ff-focus-text-new {
                background-color: rgba(239, 239, 239, .35);
                height: 36px;
                line-height: 36px;
                margin-bottom: 0;
                border-radius: 4px;
                display: flex;
                align-items: center;
                .left-focus {
                    flex: 1;
                    display: flex;
                    height: 24px;
                    line-height: 24px;
                    align-items: center;
                    margin-left: 7px;
                    .iconfont {
                        margin: 0 7px 0 4px;
                        font-size: 16px;
                    }
                    &:first-child {
                        border-right: 1px solid #ddd;
                    }
                }
                .cursorDef {
                    cursor: default;
                }
            }
        }
        &.ff-cell-checkbox{
            .checkbox-true{
                box-sizing: border-box;
                position: absolute;
                bottom: 0;
                right: -1px;
                .iconfont{
                    font-size: 25px;
                    color: @orange;
                }
            }
        }
        &:hover{
            border-color: @orange;
        }
    }
    .ff-cell-checkbox-checked {
        border-color: @orange;
    }
    .ff-cell {
        .ff-image-list {
            height: 33px;
            box-sizing: border-box;
            margin: 4px 0 8px;
            padding: 0 25px;
            position: relative;
            .ff-image-list--single {
                display: inline-block;
                width: 33px;
                height: 32px;
                text-align: center;
                img {
                    height: 100%;
                }
            }
            .ff-image-list-prev, .ff-image-list-next {
                position: absolute;
                top: 0;
                display: flex;
                align-items: center;
                justify-content: center;
                width: 16px;
                height: 100%;
                background-color: #999;
                color: #fff;
                cursor: pointer;
                outline: none;
            }
            .ff-image-list-prev {
                left: 0;
            }
            .ff-image-list-next {
                right: 0;
            }
            .ff-image-active {
                border: 1px solid @red;
                box-sizing: border-box;
                position: absolute;
                left: 0;
                right: 0;
                top: 0;
                bottom: 0;
            }
            .swiper-button-disabled {
                background-color: #ccc;
            }
        }
        .ff-text-ranking {
            align-items: center;
            padding: 0 10px;
            height: 20px;
            line-height: 20px;
            margin: 0 auto 4px;
            display: inline-block;
            background-color: @orange;
            color: #fff;
            text-align: center;
            font-weight: 400;
        }
        .ff-text-inform {
            text-align: center;
            display: block;
            text-align: center;
            color: #999;
            padding: 12px 0;
            border-top: 1px solid #DCDCDC;
        }
        .ff-text-arriveDate {
            display: block;
            margin: 0 auto 4px;
            color: #999;
            span {
                margin: 0 6px;
                color: #333;
                font-weight: bold;
            }
        }
    }
</style>
